using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_ClientRelation_ServiceManage : Member, IRequiresSessionState
{
	public string m_flag = "0";
	private string linkHead = "";
	private string tabMenu = "";
	private string actionTab = "";
	private int serviceItemID = 0;
	protected ScriptManager ScriptManager1;
	protected Label lblManage;
	protected Label lblAddOrEdit;
	protected DropDownList ddlSearchServiceType;
	protected DropDownList ddlSearchServiceMode;
	protected DropDownList ddlSearchServiceResult;
	protected TextBox txtBeginTime;
	protected TextBox txtEndTime;
	protected TextBox txtSearchClientName;
	protected TextBox txtSearchServiceTitle;
	protected Button SeachBut;
	protected DropDownList ddlDate;
	protected GridView gvManage;
	protected Literal ltrPagePanel;
	protected Button btnMoreDelete;
	protected PlaceHolder phManage;
	protected Label lblServiceTitle;
	protected Label lblClientName;
	protected Label lblContacter;
	protected Label lblServiceType;
	protected Label lblServiceMode;
	protected Label lblServiceTime;
	protected Label lblTakeTime;
	protected Label lblServiceContent;
	protected Label lblServiceResult;
	protected Label lblInputer;
	protected Label lblRemark;
	protected PlaceHolder phCheck;
	protected HiddenField hfClientID;
	protected HiddenField hfClientName;
	protected HiddenField hfContacterID;
	protected TextBox txtServiceTitle;
	protected TextBox txtClientName;
	protected HtmlAnchor showClient;
	protected DropDownList ddlContacter;
	protected DropDownList ddlServiceType;
	protected DropDownList ddlServiceMode;
	protected TextBox txtServiceTime;
	protected DropDownList ddlTakeTime;
	protected DropDownList ddlServiceResult;
	protected TextBox txtServiceContent;
	protected TextBox txtRemark;
	protected Button btnSave;
	protected Button btnBack;
	protected PlaceHolder phAddOrEdit;
	public string TabMenu
	{
		get
		{
			if (base.Request.QueryString["TabMenu"] != null)
			{
				this.tabMenu = base.Request.QueryString["TabMenu"].Trim();
			}
			return this.tabMenu;
		}
		set
		{
			this.tabMenu = value;
		}
	}
	public string ActionTab
	{
		get
		{
			if (base.Request.QueryString["action"] != null)
			{
				this.actionTab = base.Request.QueryString["action"].Trim();
			}
			else
			{
				this.actionTab = "";
			}
			return this.actionTab;
		}
		set
		{
			this.actionTab = value;
		}
	}
	public int ServiceItemID
	{
		get
		{
			if (base.Request.QueryString["serviceItemID"] != null)
			{
				this.serviceItemID = Convert.ToInt32(base.Request.QueryString["serviceItemID"].Trim());
			}
			return this.serviceItemID;
		}
		set
		{
			this.serviceItemID = value;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.OwnerPowerClientRelation(base.user.UserID))
			{
				base.WriteRightErrMsg();
			}
			this.ShowPanelDisplay(this.TabMenu);
			this.BindDropDownList();
			this.BindClientServiceItem();
			this.txtServiceTime.Text = DateTime.Now.ToString();
			if (this.ServiceItemID > 0)
			{
				this.InitPage();
			}
		}
		else
		{
			this.m_flag = Cookie.GetCookie("Contacter_m_flag");
		}
	}
	protected void ShowPanelDisplay(string DisplayName)
	{
		if (DisplayName != null)
		{
			if (!(DisplayName == "tabMnage"))
			{
				if (DisplayName == "tabAdd")
				{
					this.m_flag = "1";
					this.phManage.Visible = false;
					this.phAddOrEdit.Visible = true;
					this.showClient.Attributes.Add("onclick", "SelectKehu('" + this.txtClientName.ClientID + "');");
					if (this.ActionTab == "addinfo")
					{
						this.lblAddOrEdit.Text = "添加服务记录";
					}
					else
					{
						if (this.ActionTab == "editinfo")
						{
							this.lblAddOrEdit.Text = "修改服务记录";
						}
					}
				}
			}
			else
			{
				this.m_flag = "0";
				this.phManage.Visible = true;
				this.phAddOrEdit.Visible = false;
				this.phCheck.Visible = false;
				if (this.ActionTab == "checkinfo")
				{
					this.phManage.Visible = false;
					this.phCheck.Visible = true;
				}
			}
		}
		Cookie.SaveCookie("Contacter_m_flag", this.m_flag, 0, "");
	}
	protected void BindDropDownList()
	{
		this.ddlServiceType.bindDataToDropDownList("HL_ClientServiceItem", "ServiceType", true, false);
		this.ddlServiceMode.bindDataToDropDownList("HL_ClientServiceItem", "ServiceMode", true, false);
		this.ddlServiceResult.bindDataToDropDownList("HL_ClientServiceItem", "Result", true, false);
		this.ddlTakeTime.bindDataToDropDownList("HL_ClientServiceItem", "TakeTime", true, false);
		this.ddlSearchServiceType.bindDataToDropDownList("HL_ClientServiceItem", "ServiceType", false, false);
		this.ddlSearchServiceMode.bindDataToDropDownList("HL_ClientServiceItem", "ServiceMode", false, false);
		this.ddlSearchServiceResult.bindDataToDropDownList("HL_ClientServiceItem", "Result", false, false);
	}
	protected HoWave.Data.Model.ClientServiceItem GetClientServiceItem()
	{
		HoWave.Data.Model.ClientServiceItem clientServiceItem = new HoWave.Data.Model.ClientServiceItem();
		string text = this.txtServiceTitle.Text;
		string value = this.hfClientName.Value;
		string value2 = this.hfContacterID.Value;
		string selectedValue = this.ddlServiceType.SelectedValue;
		string selectedValue2 = this.ddlServiceMode.SelectedValue;
		string text2 = this.txtServiceTime.Text;
		string selectedValue3 = this.ddlTakeTime.SelectedValue;
		string text3 = this.txtServiceContent.Text;
		string text4 = this.ddlServiceResult.SelectedValue;
		string text5 = this.txtRemark.Text;
		HoWave.Data.Model.Client clientByClientName = HoWave.Data.Bll.Client.instance.GetClientByClientName(value, base.user.UserID);
		if (clientByClientName != null)
		{
			clientServiceItem.ClientID = new int?(clientByClientName.ClientID);
		}
		clientServiceItem.ContacterID = new int?(0);
		if (!string.IsNullOrEmpty(value2))
		{
			clientServiceItem.ContacterID = new int?(Convert.ToInt32(value2));
		}
		clientServiceItem.ServiceTitle = text;
		clientServiceItem.ServiceType = selectedValue;
		clientServiceItem.ServiceMode = selectedValue2;
		clientServiceItem.ServiceTime = new DateTime?(Convert.ToDateTime(text2));
		clientServiceItem.TakeTime = selectedValue3;
		clientServiceItem.ServiceContent = text3;
		if (string.IsNullOrEmpty(text4))
		{
			text4 = "Result_no";
		}
		clientServiceItem.ServiceResult = text4;
		clientServiceItem.Remark = text5;
		clientServiceItem.ServicePoint = 0;
		clientServiceItem.Processor = base.user.UserName;
		clientServiceItem.Inputer = base.user.UserName;
		return clientServiceItem;
	}
	private bool CheckInput()
	{
		bool result = true;
		if (!string.IsNullOrEmpty(this.txtServiceTime.Text.Trim()))
		{
			DateTime dateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
			DateTime dateTime2 = Convert.ToDateTime(this.txtServiceTime.Text.Trim());
		}
		return result;
	}
	protected void InitPage()
	{
		HoWave.Data.Model.ClientServiceItem model = BLLInstance.BllClientServiceItem.GetModel(this.ServiceItemID);
		if (model != null)
		{
			HoWave.Data.Model.Client model2 = HoWave.Data.Bll.Client.instance.GetModel(Convert.ToInt32(model.ClientID));
			if (model2 != null)
			{
				string clientName = model2.ClientName;
				this.hfClientName.Value = clientName;
				this.txtClientName.Text = clientName;
				this.lblClientName.Text = clientName;
			}
			HoWave.Data.Model.ClientContacter model3 = HoWave.Data.Bll.ClientContacter.instance.GetModel(Convert.ToInt32(model.ContacterID));
			if (model.ContacterID != 0)
			{
				this.lblContacter.Text = model3.TrueName;
			}
			this.hfContacterID.Value = model.ContacterID.ToString();
			this.ddlContacter.ddlSelect(model.ContacterID.ToString());
			this.txtServiceTitle.Text = model.ServiceTitle;
			this.ddlServiceType.ddlSelect(model.ServiceType);
			this.ddlServiceMode.ddlSelect(model.ServiceMode);
			this.txtServiceTime.Text = model.ServiceTime.ToString();
			this.ddlTakeTime.ddlSelect(model.TakeTime);
			this.txtServiceContent.Text = model.ServiceContent;
			this.ddlServiceResult.ddlSelect(model.ServiceResult);
			this.txtRemark.Text = model.Remark;
			this.lblServiceTitle.Text = model.ServiceTitle;
			this.lblServiceType.Text = this.GetDictionaryTitle(model.ServiceType);
			this.lblServiceMode.Text = this.GetDictionaryTitle(model.ServiceMode);
			this.lblServiceTime.Text = model.ServiceTime.ToString();
			this.lblTakeTime.Text = this.GetDictionaryTitle(model.TakeTime);
			this.lblServiceContent.Text = model.ServiceContent;
			this.lblServiceResult.Text = this.GetDictionaryTitle(model.ServiceResult);
			this.lblRemark.Text = model.Remark;
			this.lblInputer.Text = model.Inputer;
		}
	}
	protected void btnSave_Click(object sender, EventArgs e)
	{
		if (this.Page.IsValid && this.CheckInput())
		{
			string comeUrl = "ServiceManage.aspx?TabMenu=tabMnage";
			HoWave.Data.Model.ClientServiceItem clientServiceItem = this.GetClientServiceItem();
			if (this.ActionTab == "addinfo")
			{
				int num = BLLInstance.BllClientServiceItem.Add(clientServiceItem);
				if (num > 0)
				{
					this.WriteSuccessMsg("", "添加服务记录信息成功！", comeUrl);
				}
				else
				{
					this.WriteErrMsg("", "添加服务记录信息失败！", "");
				}
			}
			else
			{
				if (this.ActionTab == "editinfo")
				{
					clientServiceItem.ItemID = Convert.ToInt32(this.ServiceItemID);
					bool flag = BLLInstance.BllClientServiceItem.Update(clientServiceItem);
					if (flag)
					{
						this.WriteSuccessMsg("", "更新服务记录信息成功！", comeUrl);
					}
					else
					{
						this.WriteErrMsg("", "更新服务记录信息失败！", "");
					}
				}
			}
		}
	}
	protected void btnBack_Click(object sender, EventArgs e)
	{
		string url = "ServiceManage.aspx?TabMenu=tabMnage" + this.linkHead + "&pageindex";
		base.Response.Redirect(url);
	}
	protected string GetDictionaryTitle(string fieldValue)
	{
		string result = "";
		HoWave.Data.Model.Dictionary dictionary = HoWave.Data.Bll.Dictionary.instance.GetDictionary(fieldValue);
		if (dictionary != null)
		{
			result = dictionary.FieldText;
		}
		return result;
	}
	protected void BindClientServiceItem()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = this.gvManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HL_Client as c,HL_ClientServiceItem as s where s.ClientID=c.ClientID and c.Owner=" + base.user.UserID + " ";
		int pageSize = this.gvManage.PageSize;
		ClientByPage clientByPage = new ClientByPage();
		int listCount = clientByPage.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = "ROW_NUMBER() OVER (" + queryByOrder + ") as row,c.ClientName,s.* ";
		string strSQL = "select " + str + text + query;
		DataTable listPage = clientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.gvManage.DataSource = listPage;
		this.gvManage.DataBind();
		string url = "ServiceManage.aspx?TabMenu=tabMnage" + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, pageSize, listCount, "条记录&nbsp;&nbsp;每页&nbsp;" + pageSize + "&nbsp;条记录", url);
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("ServiceTime");
		if (!string.IsNullOrEmpty(text2))
		{
			this.ddlDate.ddlSelect(text2);
		}
		else
		{
			text2 = this.ddlDate.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text2))
		{
			string text3 = text2;
			if (text3 != null)
			{
				if (!(text3 == "10"))
				{
					if (!(text3 == "30"))
					{
						if (text3 == "month")
						{
							text += " and (DATEDIFF(MM,ServiceTime,GETDATE())=0)";
						}
					}
					else
					{
						text += " and (ServiceTime>=DATEADD(MM,-1,GETDATE()) and ServiceTime<=DATEADD(MM,1,getdate()))";
					}
				}
				else
				{
					text += " and (DATEDIFF(DD,ServiceTime,GETDATE())>=0 and DATEDIFF(DD,ServiceTime,GETDATE())<=10)";
				}
			}
			this.linkHead = this.linkHead + "&ServiceTime=" + text2;
		}
		string text4 = Fetch.Get("ServiceType");
		if (!string.IsNullOrEmpty(text4))
		{
			this.ddlSearchServiceType.ddlSelect(text4);
		}
		else
		{
			text4 = this.ddlSearchServiceType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text4))
		{
			text = text + " and ServiceType='" + text4 + "'";
			this.linkHead = this.linkHead + "&ServiceType=" + text4;
		}
		string text5 = Fetch.Get("ServiceMode");
		if (!string.IsNullOrEmpty(text5))
		{
			this.ddlSearchServiceMode.ddlSelect(text5);
		}
		else
		{
			text5 = this.ddlSearchServiceMode.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text5))
		{
			text = text + " and ServiceMode='" + text5 + "'";
			this.linkHead = this.linkHead + "&ServiceMode=" + text5;
		}
		string text6 = Fetch.Get("ServiceResult");
		if (!string.IsNullOrEmpty(text6))
		{
			this.ddlSearchServiceResult.ddlSelect(text6);
		}
		else
		{
			text6 = this.ddlSearchServiceResult.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text6))
		{
			text = text + " and ServiceResult='" + text6 + "'";
			this.linkHead = this.linkHead + "&ServiceResult=" + text6;
		}
		string text7 = Fetch.Get("BeginTime");
		if (!string.IsNullOrEmpty(text7))
		{
			this.txtBeginTime.Text = text7;
		}
		else
		{
			text7 = this.txtBeginTime.Text;
		}
		if (!string.IsNullOrEmpty(text7))
		{
			text = text + " and DATEDIFF(DD, ServiceTime,'" + text7 + "')<=0";
			this.linkHead = this.linkHead + "&BeginTime=" + text7;
		}
		string text8 = Fetch.Get("EndTime");
		if (!string.IsNullOrEmpty(text8))
		{
			this.txtEndTime.Text = text8;
		}
		else
		{
			text8 = this.txtEndTime.Text;
		}
		if (!string.IsNullOrEmpty(text8))
		{
			if (!string.IsNullOrEmpty(text7))
			{
				if (Convert.ToDateTime(text7) > Convert.ToDateTime(text8))
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeErr"), "");
				}
			}
			text = text + "and DATEDIFF(DD, ServiceTime,'" + text8 + "')>=0";
			this.linkHead = this.linkHead + "&EndTime=" + text8;
		}
		string text9 = Fetch.Get("KeHuName");
		if (!string.IsNullOrEmpty(text9))
		{
			this.txtSearchClientName.Text = text9;
		}
		else
		{
			text9 = this.txtSearchClientName.Text;
		}
		if (!string.IsNullOrEmpty(text9))
		{
			text = text + " and c.ClientName like '%" + text9 + "%'";
			this.linkHead = this.linkHead + "&KeHuName=" + text9;
		}
		string text10 = Fetch.Get("ServiceTitle");
		if (!string.IsNullOrEmpty(text10))
		{
			this.txtSearchServiceTitle.Text = text10;
		}
		else
		{
			text10 = this.txtSearchServiceTitle.Text;
		}
		if (!string.IsNullOrEmpty(text10))
		{
			text = text + " and ServiceTitle like '%" + text10 + "%'";
			this.linkHead = this.linkHead + "&ServiceTitle=" + text10;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		string result = "order by s.ItemID desc";
		string value = this.ddlDate.SelectedValue.Trim();
		if (!string.IsNullOrEmpty(value))
		{
			result = "order by s.ServiceTime desc";
		}
		string value2 = this.txtBeginTime.Text.Trim();
		string value3 = this.txtEndTime.Text.Trim();
		if (!string.IsNullOrEmpty(value2) || !string.IsNullOrEmpty(value3))
		{
			result = "order by s.ServiceTime desc";
		}
		return result;
	}
	protected void gvManage_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvManage_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvManage.PageIndex = e.NewPageIndex;
		this.BindClientServiceItem();
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string commandName = e.CommandName;
		if (commandName == "MoreDelete")
		{
			string text = Text.CheckNumList(Fetch.GetOrPost("IdSelect"));
			if (text != "")
			{
				bool flag = false;
				string text2 = text;
				string[] array = text2.Split(new char[]
				{
					','
				});
				for (int i = 0; i < array.Length; i++)
				{
					flag = BLLInstance.BllClientServiceItem.DeleteList(array[i]);
				}
				if (flag)
				{
					this.WriteErrMsg("", "批量信息删除成功！", "ServiceManage.aspx?TabMenu=tabMnage" + this.linkHead + "&pageindex");
				}
			}
			else
			{
				this.WriteErrMsg("", "请选您要删除的信息", "");
			}
		}
		else
		{
			if (commandName == "CheckInfo")
			{
				string text3 = e.CommandArgument.ToString();
				if (!string.IsNullOrEmpty(text3))
				{
					base.Response.Redirect("ServiceManage.aspx?TabMenu=tabMnage&action=checkinfo&serviceItemID=" + text3);
				}
			}
			else
			{
				if (commandName == "EditInfo")
				{
					string text3 = e.CommandArgument.ToString();
					if (!string.IsNullOrEmpty(text3))
					{
						base.Response.Redirect("ServiceManage.aspx?TabMenu=tabAdd&action=editinfo&serviceItemID=" + text3);
					}
				}
				else
				{
					if (commandName == "DelInfo")
					{
						string text3 = e.CommandArgument.ToString();
						HoWave.Data.Model.ClientServiceItem model = BLLInstance.BllClientServiceItem.GetModel(Convert.ToInt32(text3));
						if (model != null)
						{
							bool flag2 = BLLInstance.BllClientServiceItem.Delete(Convert.ToInt32(text3));
							if (flag2)
							{
								this.WriteErrMsg("", "删除成功！", "ServiceManage.aspx?TabMenu=tabMnage" + this.linkHead + "&pageindex");
							}
						}
					}
				}
			}
		}
		this.BindClientServiceItem();
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.m_flag = "0";
		this.BindClientServiceItem();
	}
}
